﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Pahan.McuFusion.Common
{
    [Serializable]
    public class MemoryClassInfo
    {
        public MemoryClassInfo(String name, int memorySize, int pageSize)
            : this(name, memorySize, pageSize, 0xFF)
        {
        }
        
        public MemoryClassInfo(String name, int memorySize, int pageSize, byte emptyValue)
            : this(name, memorySize, pageSize, emptyValue, true, true, true)
        {
        }

        public MemoryClassInfo(String name, int memorySize, int pageSize, byte emptyValue,
            bool canRead, bool canWrite, bool canErase)
        {
            Assert.NotNullOrEmpty(name, "name");
            Assert.Greater(memorySize, "memorySize", 0);
            Assert.Greater(pageSize, "pageSize", 0);
            this.Name = name;
            this.MemorySize = memorySize;
            this.PageSize = pageSize;
            this.EmptyValue = emptyValue;
            this.CanRead = canRead;
            this.CanWrite = canWrite;
            this.CanErase = canErase;
        }

        /// <summary>
        /// Memory class name.
        /// </summary>
        public String Name
        {
            get; 
            private set;
        }

        /// <summary>
        /// The size of the memory.
        /// </summary>
        public int MemorySize
        {
            get; 
            private set;
        }

        /// <summary>
        /// The size of the page.
        /// </summary>
        public int PageSize
        {
            get;
            private set;
        }

        /// <summary>
        /// The content of the empty memory.
        /// </summary>
        public byte EmptyValue
        {
            get;
            private set;
        }

        /// <summary>
        /// The number of pages.
        /// </summary>
        public int PageCount
        {
            get
            {
                return MemorySize / PageSize;
            }
        }

        /// <summary>
        /// Gets whether the memory can be read.
        /// </summary>
        public bool CanRead
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets whether the memory can be written.
        /// </summary>
        public bool CanWrite
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets whether the memory can be erased.
        /// </summary>
        public bool CanErase
        {
            get;
            private set;
        }
    }
}
